package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    List<User> selectList(UserDto userDto);

    /**
     * 添加用户,补全uesr全部属性
     */
    @Insert("insert into user(username,password,name,phone,email,user.gender,user.status,user.dept_id,user.role_id,user.image,user.remark,create_time,update_time) values (#{username},#{password},#{name},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
    void insert(User user);

    void deleteByIds(List<Integer> ids);

    @Select("select * from user where id=#{id}")
    User getById(Integer id);

    void update(User user);

    @Select("select u.* from role r,user u where u.role_id = r.id and r.label =#{label} and u.status = 1")
    List<User> listByRole(String roleLabel);

    @Select("select u.* from dept d,user u where u.dept_id = d.id and d.id = #{deptId}")
    List<User> listByDept(Integer deptId);

    @Select("select u.*,r.label roleLabel from user u left join role r on u.role_id = r.id where username = #{username}")
    User getByUsername(String username);
}
